package cn.matezk.cloud.framework;

import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.iot.v20180123.IotClient;
import com.tencentcloudapi.iotexplorer.v20190423.IotexplorerClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TencentConfig {
    @Value("${tencent.endpoint}")
    private String endpoint;
    @Value("${tencent.region}")
    private String region;
    @Value("${tencent.secret-id}")
    private String secretId;
    @Value("${tencent.secret-key}")
    private String secretKey;

    @Bean
    public IotexplorerClient explorerClient() {
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setEndpoint(endpoint);
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setHttpProfile(httpProfile);
        Credential credential = new Credential(secretId, secretKey);
        return new IotexplorerClient(credential, region, clientProfile);
    }

    @Bean
    public IotClient iotClient() {
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setEndpoint("iot.cloud.tencent.com");
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setHttpProfile(httpProfile);
        Credential credential = new Credential(secretId, secretKey);
        return new IotClient(credential, region, clientProfile);
    }
}
